package com.molichuxing.services.business.service.impl;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.framework.exception.BizException;
import com.molichuxing.framework.utils.CheckIdCardUtil;
import com.molichuxing.framework.utils.DateUtil;
import com.molichuxing.framework.utils.ObjectCastUtil;
import com.molichuxing.services.business.convertor.Convert;
import com.molichuxing.services.business.dto.request.create.UserBizCreateDto;
import com.molichuxing.services.business.dto.request.modify.DrivingLicenseBizModifyDto;
import com.molichuxing.services.business.dto.request.modify.UserBizModifyDto;
import com.molichuxing.services.business.dto.response.DrivingLicenseBizDto;
import com.molichuxing.services.business.dto.response.UserBizDto;
import com.molichuxing.services.business.dto.response.UserDetailBizDto;
import com.molichuxing.services.business.dto.response.UserPortraitBizDto;
import com.molichuxing.services.business.service.UserBizService;
import com.molichuxing.services.infrastructure.dto.request.create.DrivingLicenseAuditLogCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.IdentityCardCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.UserCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.UserDetailCreateDto;
import com.molichuxing.services.infrastructure.dto.request.modify.DrivingLicenseModifyDto;
import com.molichuxing.services.infrastructure.dto.request.modify.IdentityCardModifyDto;
import com.molichuxing.services.infrastructure.dto.request.modify.UserDetailModifyDto;
import com.molichuxing.services.infrastructure.dto.response.DrivingLicenseDto;
import com.molichuxing.services.infrastructure.dto.response.IdentityCardDto;
import com.molichuxing.services.infrastructure.dto.response.UserDetailDto;
import com.molichuxing.services.infrastructure.dto.response.UserDto;
import com.molichuxing.services.infrastructure.service.*;
import com.molichuxing.services.property.UserSexEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liyg
 * 用户组合服务实现类
 * 2019-08-13
 */
@Service("userBizService")
public class UserBizServiceImpl implements UserBizService {

    private final static String SEX = "M";

    @Autowired
    private UserService userService;

    @Autowired
    private UserDetailService userDetailService;

    @Autowired
    private IdentityCardService identityCardService;

    @Autowired
    private DrivingLicenseService drivingLicenseService;

    @Autowired
    private DrivingLicenseAuditLogService drivingLicenseAuditLogService;

    /**
     * 根据用户id获取用户信息 (包括身份证基本信息)
     *
     * @param userId
     * @return
     */
    @Override
    public UserBizDto getUser(Integer userId) {
        UserDto userDto = userService.getUser(userId);
        UserBizDto userBizDto = Convert.toUserBizDto(userDto);
        if (null == userBizDto) {
            return userBizDto;
        }

        UserDetailDto userDetail = userDetailService.getUserDetail(userId);
        if (null != userDetail) {
            userBizDto.setRegionId(userDetail.getRegionId());
        }

        //身份证信息
        IdentityCardDto identityCard = identityCardService.getIdentityCard(userId);
        if (null != identityCard) {
            userBizDto.setIdNumber(identityCard.getIdNumber());
        }

        return userBizDto;
    }

    /**
     * 根据用户身份证号获取用户信息 (包括身份证基本信息)
     *
     * @param idNumber
     * @return
     */
    @Override
    public UserBizDto getUser(String idNumber) {

        if (StringUtils.isAllBlank(idNumber)) {
            return null;
        }
        //身份证信息
        IdentityCardDto identityCard = identityCardService.getIdentityCard(idNumber);
        if (null == identityCard) {
            return null;
        }
        UserDto userDto = userService.getUser(identityCard.getId());
        if (null == userDto) {
            throw new BizException(101, "身份证信息异常");
        }
        UserBizDto userBizDto = Convert.toUserBizDto(userDto);
        userBizDto.setIdNumber(identityCard.getIdNumber());
        return userBizDto;
    }

    /**
     * 根据用户身份证号获取用户信息 (包括身份证基本信息)
     *
     * @param openId
     * @return
     */
    @Override
    public UserBizDto getUserByOpenId(String openId) {
        UserDto userDto = userService.getUser(openId);
        UserBizDto userBizDto = Convert.toUserBizDto(userDto);
        if (null == userBizDto) {
            return userBizDto;
        }
        Integer userId = userDto.getId();
        UserDetailDto userDetail = userDetailService.getUserDetail(userId);
        if (null != userDetail) {
            userBizDto.setRegionId(userDetail.getRegionId());
        }

        //身份证信息
        IdentityCardDto identityCard = identityCardService.getIdentityCard(userId);
        if (null != identityCard) {
            userBizDto.setIdNumber(identityCard.getIdNumber());
        }
        return userBizDto;
    }

    /**
     * 根据用户身份证号获取用户信息 (包括身份证基本信息)
     *
     * @param phone
     * @return
     */
    @Override
    public UserBizDto getUserByPhone(String phone) {

        UserDto userDto = userService.getUserByPhone(phone);
        UserBizDto userBizDto = Convert.toUserBizDto(userDto);
        if (null == userBizDto) {
            return userBizDto;
        }

        Integer userId = userBizDto.getId();
        UserDetailDto userDetail = userDetailService.getUserDetail(userId);
        if (null != userDetail) {
            userBizDto.setRegionId(userDetail.getRegionId());
        }

        //身份证信息
        IdentityCardDto identityCard = identityCardService.getIdentityCard(userId);
        if (null != identityCard) {
            userBizDto.setIdNumber(identityCard.getIdNumber());
        }
        return userBizDto;
    }

    /**
     * 根据用户id获取用户信息 (包括身份证基本信息)
     *
     * @param userIds
     * @return
     */
    @Override
    public Map<Integer, UserBizDto> getUsers(List<Integer> userIds) {

        Map<Integer, UserDto> userMap = userService.getUsers(userIds);
        if (null == userMap) {
            return null;
        }

        Map<Integer, UserBizDto> map = new HashMap<>(userMap.size());
        for (Integer key : userMap.keySet()) {
            UserDto userDto = userMap.get(key);
            UserBizDto userBizDto = Convert.toUserBizDto(userDto);
            map.put(key, userBizDto);
        }

        Map<Integer, IdentityCardDto> identityCardsMap = identityCardService.getIdentityCards(userIds);
        for (UserBizDto dto : map.values()) {
            IdentityCardDto identityCardDto = null == identityCardsMap ? null : identityCardsMap.get(dto.getId());
            dto.setIdNumber(identityCardDto == null ? null : identityCardDto.getIdNumber());
        }
        return map;
    }

    /**
     * 根据用户id获取用户信息 (包括身份证基本信息和驾驶证信息)
     *
     * @param userId
     * @return
     */
    @Override
    public UserDetailBizDto getUserDetail(Integer userId) {
        UserDto userDto = userService.getUser(userId);
        UserDetailDto userDetail = userDetailService.getUserDetail(userId);
        UserDetailBizDto userDetailBizDto = Convert.toUserDetailBizDto(userDto, userDetail);
        if (null == userDetailBizDto) {
            return userDetailBizDto;
        }

        IdentityCardDto identityCard = identityCardService.getIdentityCard(userId);
        if (null != identityCard) {
            String idNumber = identityCard.getIdNumber();
            userDetailBizDto.setIdNumber(idNumber);
        }

        DrivingLicenseDto drivingLicense = drivingLicenseService.getDrivingLicense(userId);
        if (null != drivingLicense) {
            String licenseCode = drivingLicense.getLicenseCode();
            userDetailBizDto.setLicenseCode(licenseCode);
            String model = drivingLicense.getModel();
            userDetailBizDto.setModel(model);
        }

        return userDetailBizDto;
    }


    /**
     * 获取驾驶证列表
     *
     * @param mapParam 参数
     *                 key:userName
     *                 String 用户名 非必填
     *                 key:phone
     *                 String 用户手机号 非必填
     *                 key:name
     *                 String 驾驶证姓名 非必填
     *                 key:status
     *                 Integer 验证状态 非必填
     *                 key:pageNum
     *                 Integer 当前页
     *                 key:pageSize
     *                 Integer 每页显示条数
     * @return
     */
    @Override
    public Paged<DrivingLicenseBizDto> getDrivingLicenseList(Map<String, Object> mapParam) {

        String userName = ObjectCastUtil.castString(mapParam.get("userName"));
        String phone = ObjectCastUtil.castString(mapParam.get("phone"));

        if (StringUtils.isNoneBlank(userName) || StringUtils.isNoneBlank(phone)) {
            UserDto userBeanDto = userService.getUser(userName, null, phone);
            if (null == userBeanDto) {
                return null;
            }
            mapParam.put("userId", userBeanDto.getId());
        }


        Paged<DrivingLicenseDto> paged = drivingLicenseService.getDrivingLicenseList(mapParam);
        if (null == paged) {
            return null;
        } else if (paged.isEmpty()) {
            return new Paged<>(null, paged.getTotal(), paged.getPageSize());
        }

        List<DrivingLicenseBizDto> drivingLicenseBizDtoList = Convert.toDrivingLicenseBizDto(paged.getList());

        List<Integer> userIds = new ArrayList<>();
        for (DrivingLicenseBizDto dto : drivingLicenseBizDtoList) {
            Integer id = dto.getId();
            userIds.add(id);
        }

        Map<Integer, UserDto> map = userService.getUsers(userIds);
        if (null != map) {
            for (DrivingLicenseBizDto dto : drivingLicenseBizDtoList) {
                UserDto userDto = map.get(dto.getId());
                dto.setUserName(userDto == null ? null : userDto.getName());
                dto.setPhone(userDto == null ? null : userDto.getPhone());
            }
        }

        Long total = paged.getTotal();
        Integer pages = paged.getPages();
        Paged<DrivingLicenseBizDto> page = new Paged<>(drivingLicenseBizDtoList, total, pages);
        return page;
    }

    /**
     * 修改用户个人信息
     *
     * @param modifyDto
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 5000, rollbackFor = Exception.class)
    public Boolean modifyUser(UserBizModifyDto modifyDto) {
        Integer userId = modifyDto.getId();
        UserDto userDto = userService.getUser(userId);
        if (null == userDto) {
            throw new BizException(101, "不存在该用户信息");
        }

        IdentityCardDto identityCardDto = identityCardService.getIdentityCard(modifyDto.getIdNumber());
        if (null != identityCardDto) {
            if (!userId.equals(identityCardDto.getId())) {
                throw new BizException(101, "该身份证已存在用户信息");
            }
        }

        userService.modifyUser(modifyDto.getRealName(), modifyDto.getEmail(), modifyDto.getAddress(), userId);
        String sex = CheckIdCardUtil.getGenderByIdCard(modifyDto.getIdNumber());
        String birthDay = CheckIdCardUtil.getBirthByIdCard(modifyDto.getIdNumber());

        UserDetailDto userDetail = userDetailService.getUserDetail(userId);
        if (null != userDetail) {
            UserDetailModifyDto detailModifyDto = new UserDetailModifyDto();
            detailModifyDto.setId(modifyDto.getId());
            detailModifyDto.setRegionId(modifyDto.getRegionId());
            detailModifyDto.setSex(UserSexEnum.WOMAN.getValue());
            if (SEX.equals(sex)) {
                detailModifyDto.setSex(UserSexEnum.MAN.getValue());
            }
            detailModifyDto.setBirthday(DateUtil.parseDateFormat(birthDay));
            userDetailService.modifyRegionId(detailModifyDto);
        } else {
            UserDetailCreateDto detailCreateDto = new UserDetailCreateDto();
            detailCreateDto.setId(modifyDto.getId());
            detailCreateDto.setRegionId(modifyDto.getRegionId());
            detailCreateDto.setSex(UserSexEnum.WOMAN.getValue());
            if (SEX.equals(sex)) {
                detailCreateDto.setSex(UserSexEnum.MAN.getValue());
            }
            detailCreateDto.setBirthday(DateUtil.parseDateFormat(birthDay));
            userDetailService.create(detailCreateDto);
        }

        //身份证信息
        IdentityCardDto identityCard = identityCardService.getIdentityCard(userId);
        if (null != identityCard) {
            IdentityCardModifyDto cardModifyDto = new IdentityCardModifyDto();
            cardModifyDto.setId(modifyDto.getId());
            cardModifyDto.setName(modifyDto.getRealName());
            cardModifyDto.setIdNumber(modifyDto.getIdNumber());
            cardModifyDto.setSex(UserSexEnum.WOMAN.getValue());
            if (SEX.equals(sex)) {
                cardModifyDto.setSex(UserSexEnum.MAN.getValue());
            }
            cardModifyDto.setBirthDate(DateUtil.parseDateFormat(birthDay).atStartOfDay());
            identityCardService.modifyIdNumber(cardModifyDto);
        } else {
            IdentityCardCreateDto cardCreateDto = new IdentityCardCreateDto();
            cardCreateDto.setId(modifyDto.getId());
            cardCreateDto.setName(modifyDto.getRealName());
            cardCreateDto.setIdNumber(modifyDto.getIdNumber());
            cardCreateDto.setSex(UserSexEnum.WOMAN.getValue());
            if (SEX.equals(sex)) {
                cardCreateDto.setSex(UserSexEnum.MAN.getValue());
            }
            cardCreateDto.setBirthDate(DateUtil.parseDateFormat(birthDay).atStartOfDay());
            identityCardService.create(cardCreateDto);
        }
        return true;
    }

    /**
     * 修改用户地址
     *
     * @param modifyDto
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 5000, rollbackFor = Exception.class)
    public Boolean modifyUserAddress(UserBizModifyDto modifyDto) {
        Integer userId = modifyDto.getId();
        UserDto userDto = userService.getUser(userId);
        if (null == userDto) {
            throw new BizException(101, "不存在该用户信息");
        }

        userService.modifyUserAddress(modifyDto.getAddress(), userId);

        UserDetailDto userDetail = userDetailService.getUserDetail(userId);
        if (null != userDetail) {
            Integer regionId = modifyDto.getRegionId();
            if (!regionId.equals(userDetail.getRegionId())) {
                userDetailService.modifyRegionIdById(regionId, userId);
            }
        } else {
            UserDetailCreateDto detailCreateDto = new UserDetailCreateDto();
            detailCreateDto.setId(modifyDto.getId());
            detailCreateDto.setRegionId(modifyDto.getRegionId());
            userDetailService.create(detailCreateDto);
        }

        return true;
    }

    /**
     * 修改驾驶证审核状态
     *
     * @param bizModifyDto
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 5000, rollbackFor = Exception.class)
    public Boolean modifyVerifyStatus(DrivingLicenseBizModifyDto bizModifyDto) {

        DrivingLicenseDto drivingLicense = drivingLicenseService.getDrivingLicense(bizModifyDto.getUserId());
        if (null == drivingLicense) {
            throw new BizException(101, "不存在该条信息");
        }
        DrivingLicenseModifyDto modifyDto = new DrivingLicenseModifyDto();
        BeanUtils.copyProperties(bizModifyDto, modifyDto);
        modifyDto.setId(bizModifyDto.getUserId());
        modifyDto.setVerifyTime(LocalDateTime.now());
        //保存驾驶证日志信息
        createDrivingLicenseLog(drivingLicense);
        Boolean flag = drivingLicenseService.modifyVerifyStatus(modifyDto);
        return flag;
    }

    /**
     * 查询用户画像信息（性别分布、年龄分布）
     *
     * @param isPay 是否支付过
     * @return
     */
    @Override
    public UserPortraitBizDto getUserPortraitVo(Boolean isPay) {
        UserPortraitBizDto result = new UserPortraitBizDto();
        // 查询性别分布统计
        result.setSexDistribution(userDetailService.getSexDistribution(isPay));

        // 查询用户年龄
        List<Map<String, Object>> allAges = userDetailService.getAllAge(isPay);
        result.setAgeDistribution(new ArrayList<>(6));
        if (allAges == null || allAges.isEmpty()) {
            return result;
        }

        int[] ageCount = {0, 0, 0, 0, 0, 0};
        for (Map<String, Object> allAge : allAges) {
            Object obj = allAge.get("age");
            if (obj == null) {
                continue;
            }
            Long age = (Long) obj;
            // 判断年龄
            if (age < 19L) {
                ageCount[0] += 1;
            } else if (age >= 19L && age <= 25L) {
                ageCount[1] += 1;
            } else if (age >= 26L && age <= 35L) {
                ageCount[2] += 1;
            } else if (age >= 36L && age <= 45L) {
                ageCount[3] += 1;
            } else if (age >= 46L && age <= 55L) {
                ageCount[4] += 1;
            } else {
                ageCount[5] += 1;
            }
        }
        result.getAgeDistribution().add(initAgeDistributionMap("<19岁", ageCount[0]));
        result.getAgeDistribution().add(initAgeDistributionMap("19-25岁", ageCount[1]));
        result.getAgeDistribution().add(initAgeDistributionMap("26-35岁", ageCount[2]));
        result.getAgeDistribution().add(initAgeDistributionMap("36-45岁", ageCount[3]));
        result.getAgeDistribution().add(initAgeDistributionMap("46-55岁", ageCount[4]));
        result.getAgeDistribution().add(initAgeDistributionMap(">55岁", ageCount[5]));

        return result;
    }

    private Map<String, Object> initAgeDistributionMap(String key, Object value) {
        Map<String, Object> result = new HashMap<>();
        result.put("key", key);
        result.put("value", value);
        return result;
    }

    /**
     * 保存驾驶证信息
     *
     * @param drivingLicense
     */
    private void createDrivingLicenseLog(DrivingLicenseDto drivingLicense) {
        DrivingLicenseAuditLogCreateDto createDto = new DrivingLicenseAuditLogCreateDto();
        BeanUtils.copyProperties(drivingLicense, createDto);
        createDto.setUserId(drivingLicense.getId());
        drivingLicenseAuditLogService.create(createDto);
    }

    /**
     * 添加用户信息
     *
     * @param createDto
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 5000, rollbackFor = Exception.class)
    public Boolean createUser(UserBizCreateDto createDto) {

        UserCreateDto userCreateDto = new UserCreateDto();
        userCreateDto.setPhone(createDto.getPhone());
        userCreateDto.setName(createDto.getName());
        userCreateDto.setRealName(createDto.getRealName());
        userCreateDto.setSource(createDto.getSource());
        Integer userId = userService.createUser(userCreateDto);
        if (null == userId) {
            throw new BizException(101, "注册用户信息失败");
        }

        UserDetailCreateDto detailCreateDto = new UserDetailCreateDto();
        detailCreateDto.setId(userId);
        String sex = CheckIdCardUtil.getGenderByIdCard(createDto.getIdNumber());
        detailCreateDto.setSex(UserSexEnum.WOMAN.getValue());
        if (SEX.equals(sex)) {
            detailCreateDto.setSex(UserSexEnum.MAN.getValue());
        }
        String birthDay = CheckIdCardUtil.getBirthByIdCard(createDto.getIdNumber());
        detailCreateDto.setBirthday(DateUtil.parseDateFormat(birthDay));
        Boolean flag = userDetailService.create(detailCreateDto);
        if (!flag) {
            throw new BizException(101, "注册用户信息失败");
        }

        IdentityCardCreateDto cardCreateDto = new IdentityCardCreateDto();
        cardCreateDto.setId(userId);
        cardCreateDto.setName(createDto.getRealName());
        cardCreateDto.setIdNumber(createDto.getIdNumber());
        cardCreateDto.setSex(UserSexEnum.WOMAN.getValue());
        if (SEX.equals(sex)) {
            cardCreateDto.setSex(UserSexEnum.MAN.getValue());
        }
        cardCreateDto.setBirthDate(DateUtil.parseDateFormat(birthDay).atStartOfDay());
        cardCreateDto.setAddress(createDto.getAddress());
        flag = identityCardService.create(cardCreateDto);
        if (!flag) {
            throw new BizException(101, "注册用户信息失败");
        }
        return flag;
    }

    /**
     * 修改用户个人信息（终端）
     *
     * @param modifyDto
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 5000, rollbackFor = Exception.class)
    public Boolean modifyUserTerminal(UserBizModifyDto modifyDto) {
        Integer userId = modifyDto.getId();
        UserDto userDto = userService.getUser(userId);
        if (null == userDto) {
            throw new BizException(101, "不存在该用户信息");
        }

        if (StringUtils.isAllBlank(userDto.getRealName())) {
            userService.modifyUserRealName(modifyDto.getRealName(), userId);
        }

        UserDetailDto userDetail = userDetailService.getUserDetail(userId);
        String sex = CheckIdCardUtil.getGenderByIdCard(modifyDto.getIdNumber());
        String birthDay = CheckIdCardUtil.getBirthByIdCard(modifyDto.getIdNumber());

        if (null != userDetail) {
            if (userDetail.getSex() == null || userDetail.getBirthday() == null) {
                UserDetailModifyDto detailModifyDto = new UserDetailModifyDto();
                detailModifyDto.setSex(UserSexEnum.WOMAN.getValue());
                if (SEX.equals(sex)) {
                    detailModifyDto.setSex(UserSexEnum.MAN.getValue());
                }
                detailModifyDto.setBirthday(DateUtil.parseDateFormat(birthDay));
                userDetailService.modifyBirthday(detailModifyDto);
            }
        } else {
            UserDetailCreateDto detailCreateDto = new UserDetailCreateDto();
            detailCreateDto.setId(modifyDto.getId());
            detailCreateDto.setSex(UserSexEnum.WOMAN.getValue());
            if (SEX.equals(sex)) {
                detailCreateDto.setSex(UserSexEnum.MAN.getValue());
            }
            detailCreateDto.setBirthday(DateUtil.parseDateFormat(birthDay));
            userDetailService.create(detailCreateDto);
        }

        //身份证信息
        IdentityCardDto identityCard = identityCardService.getIdentityCard(userId);
        if (null != identityCard) {
            if (identityCard.getName() == null || identityCard.getIdNumber() == null || identityCard.getAddress() == null) {
                IdentityCardModifyDto cardModifyDto = new IdentityCardModifyDto();
                cardModifyDto.setId(modifyDto.getId());
                cardModifyDto.setName(modifyDto.getRealName());
                cardModifyDto.setIdNumber(modifyDto.getIdNumber());
                cardModifyDto.setSex(UserSexEnum.WOMAN.getValue());
                if (SEX.equals(sex)) {
                    cardModifyDto.setSex(UserSexEnum.MAN.getValue());
                }
                cardModifyDto.setBirthDate(DateUtil.parseDateFormat(birthDay).atStartOfDay());
                cardModifyDto.setAddress(modifyDto.getIdNumberAddress());
                identityCardService.modifyIdNumberAddress(cardModifyDto);
            }
        } else {
            IdentityCardCreateDto cardCreateDto = new IdentityCardCreateDto();
            cardCreateDto.setId(modifyDto.getId());
            cardCreateDto.setName(modifyDto.getRealName());
            cardCreateDto.setIdNumber(modifyDto.getIdNumber());
            cardCreateDto.setSex(UserSexEnum.WOMAN.getValue());
            if (SEX.equals(sex)) {
                cardCreateDto.setSex(UserSexEnum.MAN.getValue());
            }
            cardCreateDto.setBirthDate(DateUtil.parseDateFormat(birthDay).atStartOfDay());
            cardCreateDto.setAddress(modifyDto.getIdNumberAddress());
            identityCardService.create(cardCreateDto);
        }
        return true;
    }

    /**
     * 修改用户地址+邮箱
     *
     * @param modifyDto
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 5000, rollbackFor = Exception.class)
    public Boolean modifyUserEmail(UserBizModifyDto modifyDto) {
        Integer userId = modifyDto.getId();
        UserDto userDto = userService.getUser(userId);
        if (null == userDto) {
            throw new BizException(101, "不存在该用户信息");
        }
        Boolean flag = userService.modifyUserEmail(modifyDto.getAddress(), modifyDto.getEmail(), modifyDto.getId());
        if (!flag) {
            throw new BizException(101, "修改用户信息失败");
        }
        flag = userDetailService.modifyRegionIdById(modifyDto.getRegionId(), userId);
        if (!flag) {
            throw new BizException(101, "修改用户信息失败");
        }
        return true;
    }
}
